/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ac.engin.archive;

import ac.settings.dataModel;
import static ac.settings.files.REPORT_Products_card_print;
import static ac.settings.files.REPORT_Products_in_print;
import ac.settings.sqlQuerys;
import ac.ui.utils;
import ac.uitls.propertiesOperation;
import java.awt.Component;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *The backing class for the products archive window. every window should have a backing class that extends
 * {@link ac.ui.FrameOperationTemplat}
 * @author ismail
 */
public class Products extends ac.ui.FrameOperationTemplat implements dataModel, sqlQuerys {

    double balance = 0;
    String Table_INbalance = TABLE_products_in_balance;
    String Table_balance = TABLE_products_balance;
    String Table_history = TABLE_products_move_history;
    String Tabel = TABLE_products;
    String Tabel_items = TABLE_sales_items;
    String Tabel_history = TABLE_products_move_history;

    String Tabel_items_bay = TABLE_BAY_ITEMS;

    ac.lib.database.operations db = new ac.lib.database.operations();

    /**
     * Gets a row from the products table.
     * @param id id of the product to get its data
     * @return An array containing the data from th database row.
     */
    public String[] getRow(String id) {
        String[] r;
        r = db.getRow(Tabel, "*", "id='" + id + "'");
        return r;

    }
/**
 * Gets a row from the passed table.
 * @param id id of the item to get its data
 * @param Tabel the table to select from
 * @return An array containing the data from th database row.
 */
    public String[] getRowItem(String id, String Tabel) {
        String[] r;
        r = db.getRow(Tabel, "*", "id='" + id + "'");
        return r;

    }
/**
 * Adds to the products move history the current move with the passed parameters to be used in product moves reports.
 * @param product_id the id of the product in this movement.
 * @param item_id the item that have the details of the sell or buy movements.
 * @param move_id id of the movement
 * @param MoveType type of movement, either buy or sell.
 */
    public void addToHistory(String product_id, String item_id, String move_id, String MoveType) {

        String[] pdata = this.getRow(product_id);
        //double balance = this.getbalance(product_id);

        String iTabel;
        String MTabel;

        if (MoveType.equalsIgnoreCase("in")) {

            iTabel = TABLE_BAY_ITEMS;

            MTabel = TABLE_inventory_order_input;

        } else {
            iTabel = TABLE_sales_items;

            MTabel = TABLE_inventory_order_output;
        }

        String[] itemData = getRowItem(item_id, iTabel);
        String[] MoveData = getRowItem(itemData[8], MTabel);

        String invTitle = db.getRow(tableAddstree, "*", "id=" + itemData[6])[1];

        String[][] data = {{
            "product_id",
            "product_title",
            "move_id",
            "item_id",
            "move_type",
            "quantity_after",
            "balance_in",
            "quantity",
            "date",
            "client", "inventory"

        }, {
            pdata[0],
            pdata[1], move_id, item_id, MoveType, itemData[18],
            itemData[19], itemData[5], MoveData[11], MoveData[8], invTitle
        }
        };

        db.setInsert(Tabel_history, data);

    }
/**
 * Deletes an item from the history table.
 * @param item_id id of the item to be deleted
 */
    public void deletFromHistory(String item_id) {

        db.setDelete(Tabel_history, "item_id='" + item_id + "'");

    }
/**
 * Gets the minimum sell price of a product.
 * @param id id of the product.
 * @return the minimum sell price of the product.
 */
    public double getMinSellPric(String id) {
        return Double.parseDouble(getRow(id)[4]);

    }
/**
 * Gets the minimum buy price of a product.
 * @param id id of the product.
 * @return the minimum buy price of the product.
 */
    public double getMinBayPric(String id) {
        return Double.parseDouble(getRow(id)[3]);

    }
/**
 * Gets the maximum sell price of a product.
 * @param id id of the product.
 * @return the maximum sell price of the product.
 */
    public double getMaxSellPric(String id) {
        return Double.parseDouble(getRow(id)[12]);

    }
/**
 * Gets the maximum buy price of a product.
 * @param id id of the product.
 * @return the maximum buy price of the product.
 */
    
    public double getMaxBayPric(String id) {
        return Double.parseDouble(getRow(id)[11]);

    }
/**
 * Gets the available balance of a product given its id.
 * @param id id of the product to get its balance.
 * @return the balance of the product.
 */
    public double getbalance(String id) {

        double d = 0d;

        String[] oldb_data = db.getRow(Table_balance, "*", "product_id='" + id + "'");
        if (oldb_data[2] != null) {

            d = Double.parseDouble(oldb_data[2]);

        }
        return d;

    }
/**
 * 
 * @param oINV
 * @param NINV
 * @param por
 * @param Num 
 */
    public void setConvert(String oINV, String NINV, String por, String Num) {

        this.addTobalanceInventory(por, NINV, "" + Num);
        
        this.CutbalanceInventory(por, oINV, "" + Num);

    }
/**
 * 
 * @param id 
 */
    public void removebalance(String id) {
        db.setDelete(Table_balance, "product_id='" + id + "'");
        db.setDelete(Table_INbalance, "product_id='" + id + "'");
    }
/**
 * 
 * @param id
 * @return 
 */
    public int removeInventory(String id) {

        db.setDelete(Table_INbalance, "   inventory_id='" + id + "' ");

        return db.retuenstatus;

    }
/**
 * Deletes all the related data to the products
 */
    public void removeAll() {

        if (utils.sendRemoveMssage(null) == 0) {
            try {

                db.setOpenCon();

                ResultSet r = db.getDataWithOutCon(TabelString, "*", "rowstatus ='" + rowDeleted + "'");
                while (r.next()) {

                    String myid = r.getString("id");

                    db.setDeleteWithOutCon(TabelString, Integer.parseInt(myid));
                    db.setDeleteWithOutCon(Table_balance, "product_id='" + myid + "'");
                    db.setDeleteWithOutCon(Table_INbalance, "product_id='" + myid + "'");
                }

                db.setCloseCon();
            } catch (SQLException ex) {
                Logger.getLogger(clients.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
/**
 * gets the balance available for a product in a certain inventory.
 * @param id the product id to get its balance.
 * @param inventory_id the inventory to search in
 * @return 
 */
    public double getbalance(String id, String inventory_id) {

        double d = 0d;

        String[] oldb_data = db.getRow(Table_INbalance, "*", "product_id='" + id + "' and inventory_id='" + inventory_id + "'  ");
        if (oldb_data[2] != null) {

            d = Double.parseDouble(oldb_data[2]);

        }
        return d;

    }
/**
 * gets the total balance from an inventory given its id.
 * @param inventory_id
 * @return available balance in the given inventory
 */
    public double getINbalance(String inventory_id) {

        double d = 0d;

        String[] oldb_data = db.getRow(Table_INbalance, "sum(balance) as balance", "inventory_id='" + inventory_id + "'  ");
        if (oldb_data[0] != null) {

            d = Double.parseDouble(oldb_data[0]);

        }
        return d;

    }

//<editor-fold defaultstate="collapsed" desc="process">
    /**
     * 
     * @param product_id
     * @param inventory_id
     * @param data
     * @param Status
     * @return 
     */
    private int updateBwidthIn(String product_id, String inventory_id, double data, String Status) {
        Double newB = 0d;
        Double oldB = 0d;

        String[] oldb_data = db.getRow(Table_INbalance, "*", "product_id='" + product_id + "' and  inventory_id='" + inventory_id + "' ");

        if (oldb_data[2] != null && !oldb_data[2].equalsIgnoreCase("null")) {
            oldB = Double.parseDouble(oldb_data[2]);
        }

        if (Status.equals("-")) {

            newB = oldB - data;
        } else {
            newB = oldB + data;
        }

        if (oldb_data[2] != null && !oldb_data[2].equalsIgnoreCase("null")) {
            String[][] usedata = {new String[]{"balance",}, new String[]{"" + newB}};
            db.setUpdate(Table_INbalance, usedata, "product_id='" + product_id + "' and  inventory_id='" + inventory_id + "' ");
        } else {

            String[][] usedata = {new String[]{"product_id", "inventory_id", "balance"}, new String[]{product_id, inventory_id, "" + newB}};
            db.setInsert(Table_INbalance, usedata);

        }

        return db.retuenstatus;
    }
/**
 * Updates the balance of a product either by adding or subtracting according to the given status
 * and by the given amount.
 * @param id
 * @param data
 * @param Status
 * @return 
 */
    private int Bop(String id, double data, String Status) {
        Double newB = 0d;
        Double oldB = 0d;

        String[] oldb_data = db.getRow(Table_balance, "*", "product_id='" + id + "'");

        if (oldb_data[2] != null && !oldb_data[2].equalsIgnoreCase("null")) {
            oldB = Double.parseDouble(oldb_data[2]);
        }

        if (Status.equals("-")) {

            newB = oldB - data;
        } else {
            newB = oldB + data;
        }

        if (oldb_data[2] != null && !oldb_data[2].equalsIgnoreCase("null")) {
            String[][] usedata = {new String[]{"balance"}, new String[]{"" + newB}};
            db.setUpdate(Table_balance, usedata, "product_id='" + id + "'");
        } else {

            String[][] usedata = {new String[]{"product_id", "balance"}, new String[]{id, "" + newB}};
            db.setInsert(Table_balance, usedata);

        }

        return db.retuenstatus;
    }
/**
 * Adds to the ballance of a product according to the data passed in the bill.
 * @param BillId the bill id to be used in updating the product balance.
 * @param tabel the table to get the data from.
 * @return Status of the operation
 */
    public int addTobalanceInventoryTabel(String BillId, String tabel) {

        try {
            db.setOpenCon();
            ResultSet rs = db.getDataWithOutCon(tabel, " *", "`inventory_order_id`='" + BillId + "' and  rowstatus ='" + rowNormal + "'");
            while (rs.next()) {

                updateBwidthIn(rs.getString("product"), rs.getString("inventory"), Double.parseDouble(rs.getString("quantity")), "+");

            }
            db.setCloseCon();
        } catch (SQLException ex) {
            Logger.getLogger(Products.class.getName()).log(Level.SEVERE, null, ex);
        }

        return db.retuenstatus;

    }
/**
 * Subtracts from the ballance of a product according to the data passed in the bill.
 * @param BillId the bill id to be used in updating the product balance.
 * @param tabel the table to get the data from.
 * @return Status of the operation
 */
    public int CutTobalanceInventoryTabel(String BillId, String tabel) {

        try {
            db.setOpenCon();
            ResultSet rs = db.getDataWithOutCon(tabel, " *", "`inventory_order_id`='" + BillId + "'  and  rowstatus ='" + rowNormal + "'");
            while (rs.next()) {
                updateBwidthIn(rs.getString("product"), rs.getString("inventory"), Double.parseDouble(rs.getString("quantity")), "-");
            }
            db.setCloseCon();
        } catch (SQLException ex) {
            Logger.getLogger(Products.class.getName()).log(Level.SEVERE, null, ex);
        }

        return db.retuenstatus;

    }
/**
 * 
 * @param productId
 * @param inventory_id
 * @param quantity
 * @return 
 */
    public int addTobalanceInventory(String productId, String inventory_id, String quantity) {

        return updateBwidthIn(productId, inventory_id, Double.parseDouble(quantity), "+");

    }
/**
 * 
 * @param productId
 * @param inventory_id
 * @param quantity
 * @return 
 */
    public int CutbalanceInventory(String productId, String inventory_id, String quantity) {

        return updateBwidthIn(productId, inventory_id, Double.parseDouble(quantity), "-");

    }
/**
 * 
 * @param BillId
 * @param type
 * @return 
 */
    public int Cutbalance(String BillId, String type) {
        try {
            db.setOpenCon();
            ResultSet rs = db.getDataWithOutCon(Tabel_items, " *", "`inventory_order_id`='" + BillId + "'  and  rowstatus ='" + rowNormal + "'");
            while (rs.next()) {
                Bop(rs.getString("product"), Double.parseDouble(rs.getString("quantity")), "-");
                /*
                 if (type.equalsIgnoreCase("doProcess")) {
                 addToHistory(rs.getString("product"), rs.getString("id"), BillId, "out");
                 } else if (type.equalsIgnoreCase("reProcess")) {
                 deletFromHistory(rs.getString("id"));
                 }*/

            }
            db.setCloseCon();

        } catch (SQLException ex) {
            Logger.getLogger(Products.class
                    .getName()).log(Level.SEVERE, null, ex);
        }

        return db.retuenstatus;

    }
/**
 * 
 * @param productId
 * @param quantity
 * @param item_id
 * @param type
 * @return 
 */
    public int Cutbalance(String productId, String quantity, String item_id, String type) {

        int rd = Bop(productId, Double.parseDouble(quantity), "-");

        /* if (type.equalsIgnoreCase("doProcess")) {
         addToHistory(productId, item_id, getRowItem(item_id, Tabel_items)[8], "out");
         } else if (type.equalsIgnoreCase("reProcess")) {
         deletFromHistory(item_id);
         }*/
        return rd;

    }
/**
 * 
 * @param BillId
 * @param tabel
 * @param type
 * @return 
 */
    public int CutTobalanceTabel(String BillId, String tabel, String type) {

        try {
            db.setOpenCon();
            ResultSet rs = db.getDataWithOutCon(tabel, "*", "`inventory_order_id`='" + BillId + "' and  rowstatus ='" + rowNormal + "'");
            while (rs.next()) {
                Bop(rs.getString("product"), Double.parseDouble(rs.getString("quantity")), "-");

                /*  if (type.equalsIgnoreCase("doProcess")) {
                 addToHistory(rs.getString("product"), rs.getString("id"), BillId, "out");
                 } else if (type.equalsIgnoreCase("reProcess")) {
                 deletFromHistory(rs.getString("id"));
                 }*/
            }
            db.setCloseCon();
        } catch (SQLException ex) {
            Logger.getLogger(Products.class.getName()).log(Level.SEVERE, null, ex);
        }

        return db.retuenstatus;

    }
/**
 * 
 * @param BillId
 * @param type
 * @return 
 */
    public int addTobalance(String BillId, String type) {

        try {
            db.setOpenCon();
            ResultSet rs = db.getDataWithOutCon(Tabel_items, " *", "`inventory_order_id`='" + BillId + "'  and  rowstatus ='" + rowNormal + "'");
            while (rs.next()) {

                Bop(rs.getString("product"), Double.parseDouble(rs.getString("quantity")), "+");

                /*  if (type.equalsIgnoreCase("doProcess")) {
                 addToHistory(rs.getString("product"), rs.getString("id"), BillId, "in");
                 } else if (type.equalsIgnoreCase("reProcess")) {
                 deletFromHistory(rs.getString("id"));
                 }*/
            }
            db.setCloseCon();
        } catch (SQLException ex) {
            Logger.getLogger(Products.class.getName()).log(Level.SEVERE, null, ex);
        }

        return db.retuenstatus;

    }
/**
 * 
 * @param productId
 * @param quantity
 * @param item_id
 * @param type
 * @return 
 */
    public int addTobalance(String productId, String quantity, String item_id, String type) {

        int rd = Bop(productId, Double.parseDouble(quantity), "+");

        /*   if (type.equalsIgnoreCase("doProcess")) {
         addToHistory(productId, item_id, getRowItem(item_id, Tabel_items_bay)[8], "in");
         } else if (type.equalsIgnoreCase("reProcess")) {
         deletFromHistory(item_id);
         }*/
        return rd;

    }
/**
 * 
 * @param BillId
 * @param tabel
 * @param type
 * @return 
 */
    public int addTobalanceTabel(String BillId, String tabel, String type) {

        try {
            db.setOpenCon();
            ResultSet rs = db.getDataWithOutCon(tabel, " *", "`inventory_order_id`='" + BillId + "'  and  rowstatus ='" + rowNormal + "'");
            while (rs.next()) {

                Bop(rs.getString("product"), Double.parseDouble(rs.getString("quantity")), "+");

                /*  if (type.equalsIgnoreCase("doProcess")) {
                 addToHistory(rs.getString("product"), rs.getString("id"), BillId, "in");
                 } else if (type.equalsIgnoreCase("reProcess")) {
                 deletFromHistory(rs.getString("id"));
                 }*/
            }
            db.setCloseCon();
        } catch (SQLException ex) {
            Logger.getLogger(Products.class.getName()).log(Level.SEVERE, null, ex);
        }

        return db.retuenstatus;

    }

//</editor-fold>
    /**
     * 
     * @param BillId
     * @param tabel
     * @return 
     */
    public int ChckMinLimtTabel(String BillId, String tabel) {
        String outmsges = "";
        int r = 1;

        try {

            db.setOpenCon();
            ResultSet rs = db.getDataWithOutCon(tabel, " *", "`inventory_order_id`='" + BillId + "'  and  rowstatus ='" + rowNormal + "'");
            while (rs.next()) {

                int x = ChckMinLimt(rs.getString("product"), Double.parseDouble(rs.getString("quantity")));
                if (x == 0) {
                    r = 0;
                    outmsges += rs.getString("product_title") + " - ";
                }

            }
            db.setCloseCon();
        } catch (SQLException ex) {
            Logger.getLogger(Products.class.getName()).log(Level.SEVERE, null, ex);
        }
        if (r == 0) {
            if (po.getProperty("limit.sellMessage").equalsIgnoreCase("1")) {
                utils.sendMinLimitErrorMssage(null, outmsges);
            }
        }

        if (po.getProperty("limit.sellFollow").equalsIgnoreCase("1")) {

            r = 1;
        }
        return r;

    }
/**
 * 
 * @param BillId
 * @param tabel
 * @return 
 */
    public int ChckMaxLimtTabel(String BillId, String tabel) {
        int r = 1;

        String outmsges = "";
        try {
            db.setOpenCon();
            ResultSet rs = db.getDataWithOutCon(tabel, " *", "`inventory_order_id`='" + BillId + "'  and  rowstatus ='" + rowNormal + "'");
            while (rs.next()) {

                int x = ChckMaxLimt(rs.getString("product"), Double.parseDouble(rs.getString("quantity")));
                if (x == 0) {
                    r = 0;
                    outmsges += rs.getString("product_title") + " - ";
                }
            }
            db.setCloseCon();
        } catch (SQLException ex) {
            Logger.getLogger(Products.class.getName()).log(Level.SEVERE, null, ex);
        }

        if (r == 0) {
            if (po.getProperty("limit.bayMessage").equalsIgnoreCase("1")) {
                utils.sendMaxLimitErrorMssage(null, outmsges);
            }
        }

        if (po.getProperty("limit.bayFollow").equalsIgnoreCase("1")) {

            r = 1;
        }

        return r;

    }
/**
 * Check if the passed number of an operation will result in exceeding the maximum allowed limit for a product.
 * @param pid the product id to check its max limit
 * @param num the number to check.
 * @return 1 if the number less than the limit and 0 otherwise
 */
    public int ChckMaxLimt(String pid, double num) {
        int r = 1;
        double Limit = Double.parseDouble(getRow(pid)[8]);

        double all = getbalance(pid) + num;

        if (Limit < all && Limit != 0) {

            r = 0;
        }

        return r;
    }

    /**
 * Check if the passed number of an operation will result in exceeding the minimum allowed limit for a product.
 * @param pid the product id to check its min limit
 * @param num the number to check.
 * @return 1 if the number more than the limit and 0 otherwise
 */
    public int ChckMinLimt(String pid, double num) {
        int r = 1;
        double Limit = Double.parseDouble(getRow(pid)[9]);

        double all = getbalance(pid) - num;
        all = -all;
        if (Limit < all && Limit != 0) {

            r = 0;
        }

        return r;
    }
/**
 * 
 * @param id
 * @param data
 * @return 
 */
    public int getFrombalance(String id, double data) {
        int r = 0;

        return r;

    }
/**
 * 
 * @param id
 * @return 
 */
    public String[] getInfo(String id) {
        String[] r = null;

        return r;

    }
/**
 * 
 */
    private void getoldbalance() {
    }
/**
 * 
 * @param move 
 */
    public void addTohistory(String[] move) {
    }
    propertiesOperation po = new propertiesOperation();
/**
 * 
 * @param parent
 * @param value
 * @param max
 * @param min
 * @return 
 */
    public double checkSellpricLimit(Component parent, double value, double max, double min) {
        double returnData = value;

        if (value < min) {
            if (po.getProperty("limit.sellMinPriceFollow").equalsIgnoreCase("0")) {
                returnData = min;
            }

            if (po.getProperty("limit.sellMinPriceMessage").equalsIgnoreCase("1")) {
                utils.sendPricMinMssage(parent);
            }
        }
        if (value > max) {
            if (po.getProperty("limit.sellMaxPriceFollow").equalsIgnoreCase("0")) {
                returnData = max;
            }

            if (po.getProperty("limit.sellMaxPriceMessage").equalsIgnoreCase("1")) {
                utils.sendPricMaxMssage(parent);
            }
        }
        return returnData;

    }
/**
 * 
 * @param parent
 * @param value
 * @param max
 * @param min
 * @return 
 */
    public double checkBaypricLimit(Component parent, double value, double max, double min) {
        double returnData = value;

        if (value < min) {

            if (po.getProperty("limit.bayMinPriceFollow").equalsIgnoreCase("0")) {
                returnData = min;
            }

            if (po.getProperty("limit.bayMinPriceMessage").equalsIgnoreCase("1")) {
                utils.sendPricMinMssage(parent);
            }
        }
        if (value > max) {
            if (po.getProperty("limit.bayMaxPriceFollow").equalsIgnoreCase("0")) {
                returnData = max;
            }

            if (po.getProperty("limit.bayMaxPriceMessage").equalsIgnoreCase("1")) {
                utils.sendPricMaxMssage(parent);
            }
        }
        return returnData;

    }
/**
 * 
 * @param invID 
 */
    public void retportInventoryStatus(String invID) {

        TabelString = Tabel;
        if (invID != null && !invID.equals("")) {

            String invTitle = db.getRow(tableAddstree, "*", "id=" + invID)[1];
            ac.reportes.reportes.updateReporteTitles("-", po.getWord("label.inventoryTitle") + " : " + invTitle, "-", "-", "-");

            setPrint(REPORT_Products_in_print, sqlQuerys.SQL_inventoryStatus + " where products_in_balance.inventory_id  = '" + invID + "'");

        } else {
            ac.reportes.reportes.updateReporteTitles("-", po.getWord("label.allInventory") + " ", "-", "-", "-");

            setPrint(REPORT_Products_in_print, sqlQuerys.SQL_inventoryStatus);

        }
    }
/**
 * 
 * @param Porduectid
 * @param d1
 * @param d2 
 */
    public void ProHistoryFill(String Porduectid, Date d1, Date d2) {
        try {
            db.setDelete(Table_history, "1=1");
            db.setOpenCon();
            String where = " where  sales_items.rowstatus ='" + rowNormal + "' and   inventory_order_output.rowstatus ='" + rowNormal + "'";
            if (d1 != null && d2 != null) {
                where += " and   " + ac.lib.data.dateTime.updateSerechDates("inventory_order_output.date", d1, d2);
            }
            if (Porduectid != null && !Porduectid.equals("")) {

                where += " and  sales_items.product='" + Porduectid + "'";

            }

            ResultSet rso = db.getQueryDataWithOutCon(SQL_outOrderAll + where);
            while (rso.next()) {
                addToHistory(rso.getString("sales_items_product"), rso.getString("sales_items_id"), rso.getString("inventory_order_output_id"), "out");
            }

            String wherei = " where  bay_items.rowstatus ='" + rowNormal + "'  and   inventory_order_input.rowstatus ='" + rowNormal + "'";
            if (d1 != null && d2 != null) {
                wherei += " and   " + ac.lib.data.dateTime.updateSerechDates("inventory_order_input.date", d1, d2);
            }

            if (Porduectid != null && !Porduectid.equals("")) {

                wherei += " and  bay_items.product='" + Porduectid + "'";

            }

            db.setCloseCon();

            db.setOpenCon();
            ResultSet rsi = db.getQueryDataWithOutCon(SQL_InOrderAll + wherei);
            while (rsi.next()) {
                addToHistory(rsi.getString("bay_items_product"), rsi.getString("bay_items_id"), rsi.getString("inventory_order_input_id"), "in");
            }

            db.setCloseCon();

        } catch (SQLException ex) {
            Logger.getLogger(Products.class.getName()).log(Level.SEVERE, null, ex);

            utils.sendError(null, ex.getMessage(), ex.getMessage());
        }

    }
/**
 * 
 * @param Porduectid
 * @param d1
 * @param d2 
 */
    public void retportProCard(String Porduectid, Date d1, Date d2) {
        this.ProHistoryFill(Porduectid, d1, d2);
        TabelString = Tabel;
        String[] reptitles = new String[5];

        String where = "";
        if (Porduectid != null && !Porduectid.equals("")) {
            String title = db.getRow(TABLE_products, "*", Integer.parseInt(Porduectid))[1];
            where = " where products_move_history.product_id='" + Porduectid + "'";
            reptitles[1] = po.getWord("label.product_title") + " : " + title;

        } else {

            reptitles[1] = "";

        }

        if (d1 != null && d2 != null) {
            where += " and   " + ac.lib.data.dateTime.updateSerechDates("products_move_history.date", d1, d2);
            reptitles[2] = po.getWord("label.from") + " " + d1.toString() + " " + po.getWord("label.to") + " " + d2.toString();
        } else {
            reptitles[2] = "-";
        }
        reptitles[0] = po.getWord("title.report_inputInventoryForProduct");
        reptitles[3] = "-";
        reptitles[4] = "-";
        this.reportView(REPORT_Products_card_print, where, reptitles);
    }
/**
 * 
 * @param url
 * @param where
 * @param updateTitles 
 */
    public void reportView(String url, String where, String[] updateTitles) {
        TabelString = Tabel;
        ac.reportes.reportes.updateReporteTitles(updateTitles[0],
                updateTitles[1],
                updateTitles[2],
                updateTitles[3],
                updateTitles[4]);

        setPrint(url, sqlQuerys.SQL_products_move_history + where);
    }

}
